<script>
	// import {  } from '@/utils/utils.js'
	import { indexInfo,myIndustrychain1,GetUseInfo } from '@/utils/api.js'
	export default {
		onLaunch: function() {
			uni.loadFontFace({
			  family: 'song',
				global:true,
			  source: 'url("https://invest.gztzcj.com/static/ttf/song.ttf")',
			  success() {
			  }
			})
			uni.loadFontFace({
			  family: 'kai',
				global:true,
			  source: 'url("https://invest.gztzcj.com/static/ttf/kai.ttf")',
			  success() {
			  }
			})
			
			
			
			uni.setStorageSync('isOne',10)
			// if(uni.getStorageSync('isOne')){
			// 	uni.setStorageSync('isOne',uni.getStorageSync('isOne')+1)
			// }else{
			// 	uni.setStorageSync('isOne',1)
			// }
			uni.setStorageSync('token','')
			GetUseInfo()
			if(uni.getStorageSync('myCity')&&uni.getStorageSync('myChain')){
				return myIndustrychain1({id:uni.getStorageSync('role_id'),limit:1000}).then(res=>{
					uni.setStorageSync('myChain',res.data.data)
				})
			}
			
			let that = this;
			uni.getSystemInfo({
			    success: function (res) {
						if(parseInt(res.SDKVersion.replace(/\./g, "")) > 2270){
							uni.setStorageSync('v', 'new')
						}else{
							uni.setStorageSync('v', 'old')
						}
			        let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
			        model.forEach(item => {
			            //适配iphoneX以上的底部，给tabbar一定高度的padding-bottom
			            if(res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
											uni.setStorageSync('bottom',true)
			            }
			        })
			    }
			})
			let nav_top = 0
			
			// #ifdef MP-WEIXIN
			uni.getSystemInfo({
				success: function (res) {
					console.log( res)
					if(parseInt(res.SDKVersion.replace(/\./g, "")) > 2270){
						uni.setStorageSync('v', 'new')
					}else{
						uni.setStorageSync('v', 'old')
					}
					uni.setStorageSync('windowH', res.windowHeight)
					uni.setStorageSync('windowW', res.windowWidth)
					nav_top = res.statusBarHeight + 4;
					if (res.platform.toLowerCase() == 'android') {
						nav_top += 4;
					}
					uni.setStorageSync('navH', nav_top)
				}
			})
			let boundHig = uni.getMenuButtonBoundingClientRect()
			uni.setStorageSync('navH1', nav_top + boundHig.height + 7)
			uni.setStorageSync('navH2', boundHig.height)
			// #endif
			
			// #ifndef MP-WEIXIN
			uni.getSystemInfo({
				success: function (res) {
					if(parseInt(res.SDKVersion.replace(/\./g, "")) > 2270){
						uni.setStorageSync('v', 'new')
					}else{
						uni.setStorageSync('v', 'old')
					}
					nav_top = res.statusBarHeight + 4;
					if (res.platform.toLowerCase() == 'android') {
						nav_top += 4;
					}
					uni.setStorageSync('navH', nav_top)
					uni.setStorageSync('windowH', res.windowHeight)
					uni.setStorageSync('windowW', res.windowWidth)
				}
			})
			uni.setStorageSync('navH1', 80)
			uni.setStorageSync('navH2', 30)
			// #endif
			
			// uni.setStorageSync('yun_chain',{chain_name:'',id:''})
			
			
			//初始化
			let role_id = 185
			uni.setStorageSync('role_id',role_id)
			uni.setStorageSync('appid','wxbbfefa8e80b28da7')
			
			let index = 0
			myIndustrychain1({id:role_id,limit:1000}).then(res=>{
				uni.setStorageSync('myChain',res.data.data)
				index+=1
				if(index==2){
					this.isOk()
				}
			})
			indexInfo({id:role_id}).then(res=>{
				let i =res.data
				uni.setStorageSync('chooseCity',{city_name:i.CityData.city_name,id:i.CityData.id,type:i.CityData.type,name:i.CityData.city_name})
				uni.setStorageSync('myCity',{city_name:i.CityData.city_name,id:i.CityData.id,type:i.CityData.type})
				index+=1
				if(index==2){
					this.isOk()
				}
			}).catch(err=>{
				// this.$router.push('notFound')
			})
			//是否初始化
			
			
		},
		mounted(){
				
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			isOk(){
				if(uni.getStorageSync('myCity').city_name&&uni.getStorageSync('myChain')){
					const pages = getCurrentPages();
					const currentPage = pages[pages.length - 1];
					var keys =[]
					var values=[]
					var query=[]
					if(currentPage.options){
						keys = Object.keys(currentPage.options);
						values = Object.values(currentPage.options);
						keys.forEach((item,index)=>{
							query.push(item+'='+values[index])
						})
						query =	query.join('&')
					}else{
						query =''
					}
					let url = query?`/${currentPage.route}?${query}`:`/${currentPage.route}`
					uni.reLaunch({url})
					uni.onMemoryWarning((e)=>{
						uni.reLaunch({url})
					})
					uni.setStorageSync('lat','')
					uni.setStorageSync('lng','')
					// uni.getLocation({
					// 	type: 'gcj02',
					// 	success:(res) =>{
					// 		uni.setStorageSync('lat',res.latitude)
					// 		uni.setStorageSync('lng',res.longitude)
					// 	},
					// 	fail:(err) =>{
					// 		console.log(err)
					// 		uni.showToast({
					// 			icon:'none',
					// 			title: '获取地址失败，将导致部分功能不可用',
					// 		})
					// 		uni.setStorageSync('lat','')
					// 		uni.setStorageSync('lng','')
					// 	}
					// })
				}else{
					this.isOk()
				}
			}
		}
	}
</script>
<script setup>
const style = reactive({
	height:'100%'
})
onMounted(()=>{
	var winH = uni.getStorageSync('windowH')
	var navH = uni.getStorageSync('navH')
	style.height = (winH - navH)+'px'
	console.log(style.height)
})
</script>

<style lang="scss">
/*每个页面公共css */
page{
	height: 100%; 
}
//#ifdef APP-PLUS
page{
	height: v-bind('style.height') !important
}
//#endif
.flex_sb{
	display: flex;
	justify-content: space-between;
}
.flex{
	display: flex;
}
.flex_ac{
	display: flex;
	align-items: center;
}
.flex_w{
	display: flex;
	flex-wrap: wrap;
}
@for $i from 1 through 100{
  .w#{$i}{
    width: 1% * $i;
  }
}

@for $i from 1 through 200{
  .h#{$i}{
    height: 1rpx * $i;
  }
}
</style>
